package com.itheima.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.entity.Category;
import com.itheima.entity.ShoppingCart;
import com.itheima.entity.User;
import com.itheima.jsonresult.JsonResult;
import com.itheima.service.ShoppingCartService;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 加入购物车
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    public JsonResult add(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.add(shoppingCart);
    }

    /**
     * 清空购物车
     * @param
     * @return
     */
    @DeleteMapping("/clean")
    public JsonResult delete() {
        return shoppingCartService.delete();
    }

    /**
     * 购物车列表
     * @return
     */
    @GetMapping("/list")
    public JsonResult list() {
        return shoppingCartService.shoppingCartList();
    }

    /**
     * 删除购物车商品
     * @param shoppingCart
     * @return
     */
    @PostMapping("/sub")
    public JsonResult deleteById(@RequestBody ShoppingCart shoppingCart) {
        return shoppingCartService.deleteById(shoppingCart);
    }

}
